package com.sinosoft.dsp.platform.components.helper;

import com.sinosoft.builder.templates.concept.TagElementParameterType;
import com.sinosoft.builder.templates.concept.TagElementType;
import com.sinosoft.builder.templates.concept.TagType;
import com.sinosoft.dsp.platform.components.portal.input.elements.CalendarTagElememt;
import com.sinosoft.dsp.platform.components.portal.input.elements.DateRangerTagElememt;
import com.sinosoft.dsp.platform.components.portal.input.elements.GriphImageTagElememt;
import com.sinosoft.dsp.platform.components.portal.input.elements.ISinoTagElement;
import com.sinosoft.dsp.platform.components.portal.input.elements.InputTextTagElememt;
import com.sinosoft.dsp.platform.components.portal.input.elements.RangerTagElememt;
import com.sinosoft.dsp.platform.components.portal.input.elements.RichEditorTagElememt;
import com.sinosoft.dsp.platform.components.portal.input.elements.SelectManyTagElememt;
import com.sinosoft.dsp.platform.components.portal.input.elements.SelectOneTagElememt;
import com.sinosoft.dsp.platform.components.portal.input.elements.SlideTagElememt;
import com.sinosoft.dsp.platform.components.portal.input.elements.TextareaTagElememt;
import com.sinosoft.dsp.platform.components.portal.input.elements.UploadTagElememt;
import com.sinosoft.dsp.platform.exception.SinoPlatformException;

public class TagElementHelper {

	public static ISinoTagElement createNewTagValue(TagElementType tet)
			throws SinoPlatformException {
		ISinoTagElement te = null;
		TagType at = tet.getTagType();
		if (TagType.CALENDAR == at) {
			te = new CalendarTagElememt();
			te.initValue(tet);
		} else if (TagType.DATE_RANGER == at) {
			te = new DateRangerTagElememt();
			te.initValue(tet);
		} else if (TagType.DOWNLOAD == at) {
			// TODO
		} else if (TagType.GRAPH_IMAGE == at) {
			te = new GriphImageTagElememt();
			te.initValue(tet);
		} else if (TagType.INPUT_TEXT == at) {
			te = new InputTextTagElememt();
			te.initValue(tet);
		} else if (TagType.RANGER == at) {
			te = new RangerTagElememt();
			te.initValue(tet);
		} else if (TagType.RICH_EDITOR == at) {
			te = new RichEditorTagElememt();
			te.initValue(tet);
		} else if (TagType.SELECT_MANY == at) {
			te = new SelectManyTagElememt();
			te.initValue(tet);
		} else if (TagType.SELECT_ONE == at) {
			te = new SelectOneTagElememt();
			te.initValue(tet);
		} else if (TagType.SLIDE == at) {
			te = new SlideTagElememt();
			te.initValue(tet);
		} else if (TagType.TEXTAREA == at) {
			te = new TextareaTagElememt();
			te.initValue(tet);
		} else if (TagType.UPLOAD == at) {
			te = new UploadTagElememt();
			te.initValue(tet);
		}

		return te;
	}

	public static TagElementParameterType getTagElementParameter(
			TagElementType type, String key) {
		if (type != null && type.getTagElementParameter() != null
				&& key != null) {
			for (TagElementParameterType te : type.getTagElementParameter()) {
				if (key.equals(te.getKey())) {
					return te;
				}
			}
		}
		return null;
	}

	public static boolean isEmptyTagElementParameter(
			TagElementParameterType param) {
		if (param == null || param.getValue() == null
				|| "".equals(param.getValue())) {
			return true;
		}
		return false;
	}
}
